package com.app.jzgdirector.common.retrofit;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

import okhttp3.ResponseBody;
import retrofit2.Converter;

/**
 * Created by80002037 on 2017/4/24 19:07.
 */

public final class StringConverterFactory extends Converter.Factory {
		public static StringConverterFactory create() {
				return new StringConverterFactory();
		}

		public Converter<ResponseBody, ?> fromResponseBody(Type type, Annotation[] annotations) {
				return new ConfigurationServiceConverter();
		}

		final class ConfigurationServiceConverter implements Converter<ResponseBody, String> {

				@Override
				public String convert(ResponseBody value) throws IOException {
						BufferedReader r = new BufferedReader(new InputStreamReader(value.byteStream()));
						StringBuilder total = new StringBuilder();
						String line;
						while ((line = r.readLine()) != null) {
								total.append(line);
						}
						return total.toString();
				}
		}
}